package com.evil.application.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.evil.application.pojo.entity.ApplicationFilterItem;
import com.evil.common.core.util.StreamUtil;
import org.apache.ibatis.annotations.Param;

import java.util.Collection;
import java.util.List;
import java.util.Map;

/**
 * 应用筛选项表
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
public interface ApplicationFilterItemMapper extends BaseMapper<ApplicationFilterItem> {

    List<ApplicationFilterItem> findByGroupId(@Param("filterGroupId") Long filterGroupId);

    List<ApplicationFilterItem> findByGroupIds(@Param("filterGroupIds") Collection<Long> filterGroupIds);

    default Map<Long, ApplicationFilterItem> findMapByGroupId(Long filterGroupId) {
        return StreamUtil.toMapK(this.findByGroupId(filterGroupId), ApplicationFilterItem::getFilterItemId);
    }

    default Map<Long, List<ApplicationFilterItem>> findGroupItemsByGroupIds(Collection<Long> filterGroupIds) {
        return StreamUtil.groupK(this.findByGroupIds(filterGroupIds), ApplicationFilterItem::getFilterGroupId);
    }

    default Map<Long, Map<Long, ApplicationFilterItem>> findGroupItemMapByGroupIds(Collection<Long> filterGroupIds) {
        return StreamUtil.groupAndThenTransMapK(this.findByGroupIds(filterGroupIds), ApplicationFilterItem::getFilterGroupId, ApplicationFilterItem::getFilterItemId);
    }
}
